local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill{
  name = "sj_dianjuren__chongshenglahuan",
}

Fk:loadTranslationTable{
  ["sj_dianjuren__chongshenglahuan"] = "重生拉环",
  [":sj_dianjuren__chongshenglahuan"] = "每回合限一次，你使用牌仅指定自己为目标后，可以回复1点体力或将中央区两张牌洗入牌堆。",
  ["#sj_dianjuren__chongshenglahuan"] = "重生拉环：你可以回复1点体力或将中央区两张牌洗入牌堆",
  ["#sj_dianjuren__chongshenglahuan_hp"] = "回复1点体力",
  ["#sj_dianjuren__chongshenglahuan_card"] = "将中央区两张牌洗入牌堆",
}

skel:addEffect(fk.TargetSpecified, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player:usedSkillTimes(skel.name) == 0 and data:isOnlyTarget(player)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local list,cards = {},DIY.getCenterCards(room)
    if player:isWounded() then
      table.insert(list,"#sj_dianjuren__chongshenglahuan_hp")
    end
    if #cards > 1 then
      table.insert(list,"#sj_dianjuren__chongshenglahuan_card")
    end
    if #list == 0 then return end
    local s, ret = room:askToUseActiveSkill(player,{
      skill_name = "#sj_dianjuren__chongshenglahuan_choose",
      prompt = "#sj_dianjuren__chongshenglahuan",
      extra_data = {
        skillName = skel.name,
        extra_data = {
        list = list,
        cards = cards,
      }},
    })
    if s and ret and ret.cards and ret.interaction then
      event:setCostData(self, {cards = ret.cards, i = ret.interaction})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event:getCostData(self).i == "#sj_dianjuren__chongshenglahuan_hp" then
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name,
        recoverBy = player,
      }
    else
      local ids = event:getCostData(self).cards
      local moves = {}
      for _, id in ipairs(ids) do
        table.insert(moves, {
          ids = {id},
          toArea = Card.DrawPile,
          moveReason = fk.ReasonJustMove,
          skillName = skel.name,
          drawPilePosition = math.random(#room.draw_pile),
        })
      end
      room:moveCards(table.unpack(moves))
    end
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return skel